//
//  USAlbumCoverView.m
//  us
//
//  Created by karry on 2025/4/10.
//

#import "USAlbumCoverView.h"


@implementation USAlbumCoverView


- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{

    UIView *bgContentView = [UIView new];
    _bgContentView = bgContentView;
    [self addSubview:bgContentView];
 
    
    UIImageView *bgImageView = [[UIImageView alloc]initWithImage:nil];
    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    bgImageView.layer.masksToBounds = YES;
    _bgImageView = bgImageView;
    [bgContentView addSubview:bgImageView];

    UIImageView *lineImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Property 1=1"]];
    _lineImageView = lineImageView;
    [self addSubview:lineImageView];
    
    [lineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    UIImageView *markImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Vector 74"]];
    _markImageView = markImageView;
    [self addSubview:markImageView];
    [markImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.top.mas_equalTo(lineImageView.mas_bottom);
    }];
    
}

- (void)setCoverType:(NSInteger)coverType {
    _coverType = coverType;
    
    self.lineImageView.hidden = coverType == 0 ? NO : YES;

}

- (void)setShowBookmark:(BOOL)showBookmark{
    showBookmark = showBookmark;
    self.markImageView.hidden = !showBookmark;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat corner = self.bounds.size.width * (16.95/345.f);
    corner = MAX(corner, 6);
    self.bgImageView.layer.cornerRadius = corner;
    self.bgContentView.layer.cornerRadius = corner;
    
    self.bgContentView.frame = self.bounds;
    self.bgImageView.frame = self.bounds;
    
}

- (void)setColor:(UIColor *)color{
    _color = color;
    self.bgImageView.image = nil;
    self.bgContentView.backgroundColor = color;
    self.markImageView.image = [[UIImage imageNamed:@"Vector 74"] imageWithTintColor:[color jk_darkenColor:0.1]];
}

- (UIImage *)snapshot{
    return [self.bgContentView jk_screenshot];
}

@end
